<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="url" value='${requestScope["org.springframework.web.servlet.HandlerMapping.pathWithinHandlerMapping"]}' scope="request"/>

<link rel="stylesheet" type="text/css" href="${resourcePath}/tags/zTree3.5/css/zTreeStyle.css"/>
<script type="text/javascript"src="${resourcePath}/tags/zTree3.5/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="${resourcePath}/tags/zTree3.5/js/jquery.ztree.all-3.5.min.js"></script>

<script type="text/javascript">
    function onClickTrade(e, treeId, treeNode) {
        var _url = treeNode.url;
        window.location.href="<c:url value='/testMgr.html'/>";
        alert(treeNode.id + treeNode.name);
    };
    var _setting = {
        //复选框显示
        check:{
            enable: true,
            chkStyle: "radio",
            radioType: "all"
        },
        data : {
            simpleData : {
                enable : true,//简单的数据
                idkey : "id",//本身的id
                pidkey : "pId",//父节点
                rootpid : null
            }
        },
        view : {
            selectedMulti : false,
            showLine : true,//是否显示连接线
            showIcon : true,//是否显示图标
            nameIsHTML : true,//nodes是否可以使用html标签
            showTitle : true
        },
        async : {
            enable : true,
            url : "${pageContext.request.contextPath}/settings/menu/menuList.json",
            autoParam : [ "id" ]
        }
        ,
        //点击后的触发事件
        callback : {
            onClick : onClickTrade
        }
    };
    //加载ztree
    function onloadZTree(){
        var _menus;
        $.ajax( {
            async : true, //是否异步
            cache : true, //是否使用缓存
            type : 'get', //请求方式,post
            dataType : "json", //数据传输格式
            url : "${pageContext.request.contextPath}/settings/menu/menuList.json", //请求链接
            error : function() {
                alert("加载失败");
            },
            success : function(data) {
                var _code = data.result.code;
                _menus = data.result.obj;
                console.log(_menus);
                $.fn.zTree.init($( "#treeDemo"), _setting, _menus);
//                zTree_Menu = $.fn.zTree.getZTreeObj("treeDemo" );
            }
        });
    }

    //初始化操作
    $(document).ready(function(){
        onloadZTree();
    });

    //获取所有选中节点的值
    function GetCheckedAll() {
        var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
        var nodes = treeObj.getCheckedNodes(true);
        var msg = "name--id--pid\n";
        for (var i = 0; i < nodes.length; i++) {
            msg += nodes[i].name+"--"+nodes[i].id+"--"+nodes[i].pId+"--"+nodes[i].url+"\n";
        }
    }
</script>

<div class="main_left">
    <div style="border: 1px solid mediumseagreen;width: 99%; height: 99%; margin-right: 20px;">
        <ul id="treeDemo" class="ztree"></ul>
    </div>
</div>